<template>
    <headPage :tabsIndex="2"></headPage>
    <div class="main_box information">
      <div class="navigate_view">
        <span class="navigate_text" @click="goHome">知识库</span>
        <span class="navigate_line">/</span>
        <span class="navigate_text" @click="goHome">{{ detailsInfo.zhuanyemingcheng }}</span>
        <span class="navigate_line">/</span>
        <span class="navigate_last_text">{{ detailsInfo.biaoti }}</span>
      </div>
      <div class="details" v-loading="loading">
        <div class="title">{{ detailsInfo.biaoti }}</div>
        <div class="date">{{ detailsInfo.create_time }}</div>
        <div class="parse" v-html="detailsInfo.xiangqing"></div>
      </div>
    </div>
    <footerPage></footerPage>
  </template>
  
  
  <script name="helpDetails" setup>
  import { post65e840e85b685 } from "@/utils/api.js";
  import headPage from "@/components/headPage.vue";
  import footerPage from "@/components/footerPage.vue";
  import { ref, onMounted } from "vue";
  import { useRouter, useRoute } from "vue-router";
  const router = useRouter();
  const route = useRoute();
  
  let aid = route.query.aid;
  
  onMounted(() => {
    getDetails();
  });
  // 获取详情
  let detailsInfo = ref({});
  let loading = ref(true);
  const getDetails = () => {
    post65e840e85b685({
      aid: aid,
    })
      .then((res) => {
        // console.log(res);
        loading.value = false;
        if (res.code == 1) {
          detailsInfo.value = res.data;
          detailsInfo.value.xiangqing = imgTagAddStyle(detailsInfo.value.xiangqing);
        }
      })
      .catch((err) => {
        console.log(err);
      });
  };
  function goHome() {
    router.push({
      path: "/knowledgeBase",
    });
  }
  function imgTagAddStyle(htmlstr) {
    // 正则匹配所有img标签
    // var regex0 = new RegExp("(i?)(\<img)([^\>]+\>)","gmi");
    // 正则匹配不含style="" 或 style='' 的img标签
    // eslint-disable-next-line no-useless-escape
    var regex1 = new RegExp(
      "(i?)(<img)(?!(.*?style=['\"](.*)['\"])[^>]+>)",
      "gmi"
    );
    // 给不含style="" 或 style='' 的img标签加上style=""
    htmlstr = htmlstr.replace(regex1, '$2 style=""$3');
    // console.log('增加style=""后的html字符串：' + htmlstr);
    // 正则匹配含有style的img标签
    // eslint-disable-next-line no-useless-escape
    var regex2 = new RegExp("(i?)(<img.*?style=['\"])([^>]+>)", "gmi");
    // 在img标签的style里面增加css样式(这里增加的样式：display:block;max-width:100%;height:auto;border:5px solid red;)
    htmlstr = htmlstr.replace(regex2, "$2max-width:100%;height:auto;$3");
    return htmlstr;
  }
  </script>
  
  <style lang="scss" scoped>
  .navigate_view {
    display: flex;
    align-items: center;
    padding: 0 0 12px 0;
    .navigate_text {
      font-size: 9px;
      color: #666;
      cursor: pointer;
    }
    .navigate_line {
      font-size: 9px;
      color: #bfbfbf;
      margin: 0 5px;
    }
    .navigate_last_text {
      font-size: 9px;
      color: #1f52ae;
      cursor: pointer;
    }
  }
  .information {
    margin-top: 97px;
    margin-bottom: 24px;
    padding: 18px 16px;
    //   background: #fff;
  }
  .details {
    min-height: 358px;
    background: #fff;
    padding: 26.5px 158.5px 20px;
    .title {
      font-size: 14px;
      font-weight: bold;
      text-align: center;
    }
    .date {
      padding: 15px 0 13px;
      font-size: 7px;
      color: #999;
      border-bottom: 1px solid #eee;
      text-align: center;
    }
    .parse {
      margin-top: 40px;
      font-size: 9px;
    }
  }
  
  .save_btn {
    width: 120px;
    height: 24px;
    background: #1f52ae;
    font-size: 8px;
    color: #fff;
    border-radius: 3px;
    margin: 32px 0 0 47px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }
  </style>